package cn.controller;

import cn.common.ConfigOption;
import cn.common.ExceResult;
import cn.common.GridCommon;
import cn.common.LayTable;
import cn.filter.LoginCheck;
import cn.kpi.common.Excel.domain.SubheadModel;
import cn.kpi.common.Excel.export.ExportConfigFactory;
import cn.kpi.common.Excel.export.FileExportor;
import cn.kpi.common.Excel.export.domain.common.ExportConfig;
import cn.kpi.common.Excel.export.domain.common.ExportResult;
import cn.kpi.entity.attendance.AttTbBatchEntity;
import cn.kpi.entity.payassessment.*;
import cn.kpi.entity.sys.Configure;
import cn.kpi.entity.sys.OrgEntity;
import cn.kpi.entity.sys.UserEntity;
import cn.kpi.service.common.IOrgSummaryService;
import cn.kpi.service.payassessment.IPayAssessmentService;
import cn.kpi.service.sys.IConfigureService;
import cn.kpi.service.sys.IOrgService;
import cn.kpi.service.sys.IUserService;
import org.apache.ibatis.scripting.xmltags.WhereSqlNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

import static cn.kpi.common.utils.DateUtils.getDay;
import static cn.kpi.common.utils.DateUtils.getMonth;
import static cn.kpi.common.utils.DateUtils.getYear;

@Controller
@RequestMapping("payworks")
public class PayWorksController extends BaseController {

    @Autowired
    private IConfigureService configureService;

    @Autowired
    private IOrgService iOrgService;

    @Autowired
    private IPayAssessmentService iPayAssessmentService;

    @Autowired
    private IOrgSummaryService iOrgSummaryService;

    @Autowired
    private IUserService iUserService;

    //region 工作津贴补助
    //初始化
    @RequestMapping(value = "/work_pay_dept_new")
    public String workPayDepttList(Model model) {
        try {
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH)+1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }

            if (quarter == 1){
                year =year - 1;
                quarter = 4;
            }
            else {
                quarter--;//默认上个季度
            }
            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);
//            model.addAttribute("month", month);
            model.addAttribute("type", 0);
        } catch (Exception ex) {
        }
        return "payassessment/work_pay_dept_new";
    }

    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_org_work_dept_list")
    public LayTable<Map> GetOrgTranDeptList(HttpServletRequest request) {

        List<Map> lst = null;
        LayTable<Map> layTable = new LayTable<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int month = Integer.parseInt(request.getParameter("month"));

            Calendar cal = Calendar.getInstance();
            int currentyear = cal.get(Calendar.YEAR);
            int currentmonth = cal.get(Calendar.MONTH) + 1;
            if (currentyear != year) {
                currentmonth = 12;
            }


            Integer iexit = iOrgSummaryService.GetOrgYearCount("work", year, 0);
            if (iexit == 0) {
                List<Integer> list = new ArrayList<Integer>();
                for (int i = 0; i < 12; i++) {
                    list.add(i + 1);
                }
                iOrgSummaryService.InsertOrgYearWorkBacth(list, year);
            }

            String where = "";
            where += " AND orgid IN (" + this.GetOrgListByRole() + ")";
            lst = iOrgSummaryService.GetOrgSummaryWorkList(where, year, month, "", currentmonth);

            layTable.setCode(0);
            layTable.setCount(lst.size());
            layTable.setData(lst);

        } catch (Exception e) {
            e.printStackTrace();
            layTable.setCode(500);
        }
        return layTable;
    }


    @RequestMapping(value = "/work_pay_new")
    public String TranList(Model model) {
        try {
            UserEntity loginUser = this.GetLoginUser();
            if (loginUser.getRealname().contains("开发")) {
                model.addAttribute("isadmin", true);
            } else {
                model.addAttribute("isadmin", false);
            }
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH)+1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }
            if (quarter == 1){
                year =year -1;
                quarter = 4;
            }
            else {
                quarter--;//默认上个季度
            }
            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "payassessment/work_pay_new";
    }


    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_org_work_list")
    public GridCommon<Map> GetOrgTranList(HttpServletRequest request) {

        List<Map> lst = null;
        GridCommon<Map> countlist = new GridCommon<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int month = Integer.parseInt(request.getParameter("month"));
            String strorgid = request.getParameter("orgid");
            String strstatus = request.getParameter("status");
            String where = "";
            if (this.GetOrgListByRole() != "")
                where += " AND orgid IN (" + this.GetOrgListByRole() + ")";

            Calendar cal = Calendar.getInstance();
            int currentyear = cal.get(Calendar.YEAR);
            int currentmonth = cal.get(Calendar.MONTH) + 1;
            if (currentyear != year) {
                currentmonth = 12;
            }

            if (strorgid != null && strorgid.length() > 0) {
                OrgEntity orgentity = iOrgService.GetOrgById(Long.parseLong(strorgid));
                where += " AND orgid IN ( SELECT orgid FROM t_sys_org WHERE lft>=" + orgentity.getLft() + " AND lft<="
                        + orgentity.getRgt() + ")";
            }

            Integer iexit = iOrgSummaryService.GetOrgYearCount("work", year, 0);
            if (iexit == 0) {
                List<Integer> list = new ArrayList<Integer>();
                for (int i = 0; i < 12; i++) {
                    list.add(i + 1);
                }
                iOrgSummaryService.InsertOrgYearWorkBacth(list, year);
            }

            lst = iOrgSummaryService.GetOrgSummaryWorkList(where, year, month, strstatus, currentmonth);
//            lst = iOrgSummaryService.GetOrgSummaryList(where, year, month, strstatus, currentmonth);
            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(lst);
            countlist.setStatus(0);
            countlist.setMsg("");
            countlist.setCountRecord(lst.size());

        } catch (Exception e) {
            e.printStackTrace();
            countlist.setCurrentPage(1);
            countlist.setPageSize(10);
            countlist.setItems(null);
            countlist.setStatus(1);
            countlist.setMsg(e.getMessage());
        }
        return countlist;
    }


    //补助生成
    @ResponseBody
    @RequestMapping(value = "/create_work_pay")
    public ExceResult CreateAttTbNoDetail(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        int iResult = 0;
        try {
            String strorgid = request.getParameter("orgid");
            String stryear = request.getParameter("year");
            String strmonth = request.getParameter("month");
            String[] orgids = strorgid.split(",");


            Long byuserid = this.GetLoginUserId();
            UserEntity byuser = this.GetUserById(byuserid);
            int year = Integer.parseInt(stryear);
            int month = Integer.parseInt(strmonth);
            int quarter = getquarter(month);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(sdf.parse(year + "-" + month + "-1"));
            int countday = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

            String months = getmonth(quarter);

            for (int i = 0; i < orgids.length; i++) {

                Long orgid = Long.parseLong(orgids[i]);
                AttTbBatchEntity entity = new AttTbBatchEntity();
                entity.setByuserid(byuserid);
                entity.setDay(0);
                entity.setDays(countday);
                entity.setMonth(month);//以最后一个月为季度判断
                entity.setOrgid(orgid);
                entity.setYear(year);
                entity.setQuarter(quarter);

                //取出固定扣减人员
                String duwhere =  " AND szdw in (" + orgid + ")";
                List<DpUserListEntity> dpUserListEntities = iPayAssessmentService.getDetpUserList(duwhere);
                Map<String,Float> gduser = new HashMap<>();
                for (DpUserListEntity dpUserListEntity : dpUserListEntities) {
                    gduser.put(dpUserListEntity.getCardno(),dpUserListEntity.getMoney());
                }


                int iExit = iOrgSummaryService.GetExitOrgSummary(orgid, year, month, "work");//每季度最后一个月代表该季
                if (iExit > 0) {
                    result.setCode(400);
                    result.setResult(iExit);
                    result.setMsg("该机构该年度该季已生成补助(" + year + "年" + quarter + "季)");
                    return result;
                }

                for (String m : months.split(",")) {
                    Integer mint = Integer.valueOf(m);
                    int isExit = iOrgSummaryService.GetExitOrgStatusSummary(orgid, year, mint, "att", "2");//是否已经归档
                    if (isExit == 0) {
                        result.setCode(400);
                        result.setResult(isExit);
                        result.setMsg(mint+"月考勤还未归档，请稍后填报！");
                        return result;
                    }
                }

                List<OrgEntity> orgEntities = new ArrayList<>();
                String orgs = "";
                String where = "";
                orgEntities = GetOrgListByOrgid(orgid);

                for (OrgEntity orgEntity : orgEntities) {
                    if (orgs.equals(""))
                        orgs = String.valueOf(orgEntity.getOrgid());
                    else
                        orgs += "," + orgEntity.getOrgid();
                }

                if (orgs.length() > 0) {
                    where += " AND szdw IN (" + orgs + ")";
                }

                List<WorkPayVoEntity> lst = new ArrayList<>();

                boolean novacastatus  = true;
                for (String mstr : months.split(",")) {
                    //11.3 工作津贴，也只统计在职人员
                    where += " AND userstatus='在职'";
                    //这里循环出要统一插入的数据
                    List<UserEntity> userlst = iUserService.GetUserListWorkByWhere(where, stryear, mstr);//动态月

                    for (UserEntity userEntity : userlst) {
                        if (userEntity.getUserstatus() != null && userEntity.getUserstatus().equals("在职")) {
                            WorkPayVoEntity voEntity = new WorkPayVoEntity();
                            voEntity.setMonth(mstr);//动态月
                            voEntity.setYear(stryear);
                            voEntity.setCardno(userEntity.getCardno());
                            voEntity.setUserid(userEntity.getUserid());
                            voEntity.setOrgid(userEntity.getSzdw());
                            voEntity.setRealname(userEntity.getRealname());
                            voEntity.setOrgname(userEntity.getOrgname());
                            voEntity.setUserstatus(userEntity.getUserstatus());
                            voEntity.setRsgxszdw(userEntity.getRsgxszdw());
                            voEntity.setRsgxszdwname(userEntity.getRsgxorgname());
                            if (userEntity.getWorkdeptnum() == null) userEntity.setWorkdeptnum("0");
                            if (userEntity.getWorkleadernum() == null) userEntity.setWorkleadernum("0");
                            if (userEntity.getWorkyearnum() == null) userEntity.setWorkyearnum("0");
                            Float originMoney = Float.valueOf(userEntity.getWorkdeptnum()) + Float.valueOf(userEntity.getWorkleadernum()) + Float.valueOf(userEntity.getWorkyearnum());
                            if (userEntity.getFallVaca() == null) userEntity.setFallVaca(0f);
                            if (userEntity.getMatterVaca() == null) userEntity.setMatterVaca(0f);
                            Float vaca = userEntity.getFallVaca() + userEntity.getMatterVaca();
                            if (vaca <= 0) {
                                vaca = 0f;
                            }else{
                                novacastatus = false;
                            }
                            double middle = 0;
                            if (vaca >= 3) middle = (vaca - 3f) * (originMoney / 21.75);
                            Float lostMoney = (float) middle;
                            if(gduser.containsKey(voEntity.getCardno())){//有这个人，直接扣减扣减额度！
                                lostMoney = gduser.get(voEntity.getCardno());
                                novacastatus = false;
                            }
                            else {
                                lostMoney = (float) (Math.round(lostMoney * 100)) / 100;
                                //设置最大值
                                if(lostMoney > originMoney){
                                    lostMoney = originMoney;
                                }
                            }

                            voEntity.setOriginMoney(originMoney);
                            voEntity.setLostMoney(lostMoney.toString());

                            voEntity.setStatus(0);
                            voEntity.setByuserid(byuser.getUserid());
                            voEntity.setByuserrsgxszdw(byuser.getRsgxszdw());
                            voEntity.setByuserrsgxszdwname(byuser.getRsgxorgname());
                            voEntity.setByuserszdw(byuser.getSzdw());
                            voEntity.setByuserszdwname(byuser.getOrgname());
                            voEntity.setByuseruserstatus(byuser.getUserstatus());
                            lst.add(voEntity);
                        }
                    }
                }

                if(novacastatus){
                    for (WorkPayVoEntity workPayVoEntity : lst) {
                        workPayVoEntity.setStatus(2);//直接归档
                    }

                    entity.setStatus(2);//直接归档
                }

                iResult = iPayAssessmentService.createWorkPayList(entity, lst);
            }
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }

    private Integer getquarter(int month) {
        int quarter = 1;
        switch (month) {
            case 1:
            case 2:
            case 3:
                quarter = 1;
                break;
            case 4:
            case 5:
            case 6:
                quarter = 2;
                break;
            case 7:
            case 8:
            case 9:
                quarter = 3;
                break;
            case 10:
            case 11:
            case 12:
                quarter = 4;
                break;
        }
        return quarter;
    }


    //工作津贴获取
    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_work_dept_list")
    public LayTable<WorkSeanVoEntity> GetSummaryList(HttpServletRequest request) {
        LayTable<WorkSeanVoEntity> layTable = new LayTable<WorkSeanVoEntity>();
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            String year = request.getParameter("year");
            String month = request.getParameter("month");
            String quarter = request.getParameter("quarter");
            int quarterInt = Integer.parseInt(quarter);
            String orgid = request.getParameter("orgid");
            String realname = request.getParameter("realname");
            String orgsummaryid = request.getParameter("orgsummaryid");

            String month1 = "";
            String month2 = "";
            String month3 = "";

            String where = "";
            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }
            if (quarterInt > 0) {
                String[] months = getmonth(quarterInt).split(",");
                month1 = months[0];
                month2 = months[1];
                month3 = months[2];
            }

//            if(orgsummaryid.length()>0){
//                where +=" AND orgsummaryid = "+orgsummaryid;
//            }

            if (orgid.length() > 0) {
                where += " AND orgid IN (" + orgid + ")";
            }

            if (realname != null && realname.length() > 0) {
                where += " AND userid IN (SELECT userid FROM t_sys_user WHERE cardno LIKE '%" + realname + "%'  or realname LIKE '%" + realname + "%')";
            }

            int beginrow = (page - 1) * limit;
            int endrow = limit;

            String whereLimit = " LIMIT " + beginrow + "," + endrow;
            List<WorkSeanVoEntity> lst = iPayAssessmentService.getWorkSeanPayEntiy(where, whereLimit, month1, month2, month3, month);
            for (int i = 0; i < lst.size(); i++) {
                //11.4日修改，加入了null就去取部门的逻辑
                String workpernum1="",workpernum2="",workpernum3="";
                Float downsum = 0f;
                lst.get(i).setRownum(i+1);
                long userid = lst.get(i).getUserid();
                if(lst.get(i).getWorkpernum1()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum1(getWorkPernum(year, month1, userid));
                }else {
                    workpernum1 = lst.get(i).getWorkpernum1();
                    downsum += Float.valueOf(workpernum1);
                }
                if(lst.get(i).getWorkpernum2()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum2(getWorkPernum(year, month2, userid));
                }else {
                    workpernum2 = lst.get(i).getWorkpernum2();
                    downsum += Float.valueOf(workpernum2);
                }
                if(lst.get(i).getWorkpernum3()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum3(getWorkPernum(year, month3, userid));
                }else {
                    workpernum3 = lst.get(i).getWorkpernum3();
                    downsum += Float.valueOf(workpernum3);
                }

                downsum = 0 -downsum;
                if(downsum != 0){
                    if(lst.get(i).getDownreason()==null||lst.get(i).getDownreason().equals("")){
                        lst.get(i).setDownreason("根据考勤情况扣减");
                    }
                }

                //不是钱合计，而是减扣金额合计
                lst.get(i).setWorkpernumsum(downsum.toString());
            }
            List<WorkSeanVoEntity> lstcount = iPayAssessmentService.getWorkSeanPayEntiy(where, "", month1, month2, month3, month);
            int iCount = lstcount.size();
            layTable.setCode(0);
            layTable.setCount(iCount);
            layTable.setData(lst);

        } catch (Exception e) {
            layTable.setCode(500);
        }
        return layTable;
    }

    private String getWorkPernum(String year, String month1, long userid) throws Exception {
        String workpernum1;
        String whereOrg = " AND userid = "+userid;
        List<UserEntity> userlst = iUserService.GetUserListWorkByWhere(whereOrg, year, month1);//动态月
        if(userlst.size()>0)
            workpernum1 = userlst.get(0).getOrgname();
        else
            workpernum1 = null;
        return workpernum1;
    }


    private String getmonth(Integer sqn) {
        String ret = "";
        switch (sqn) {
            case 1:
                ret = "1,2,3";
                break;
            case 2:
                ret = "4,5,6";
                break;
            case 3:
                ret = "7,8,9";
                break;
            case 4:
                ret = "10,11,12";
                break;
        }
        return ret;
    }

    private String getLastMonth(Integer sqn) {
        String ret = "";
        switch (sqn) {
            case 1:
                ret = "3";
                break;
            case 2:
                ret = "6";
                break;
            case 3:
                ret = "9";
                break;
            case 4:
                ret = "12";
                break;
        }
        return ret;
    }

    //工作津贴修改
    @RequestMapping(value = "/update_work_pay", method = RequestMethod.POST)
    @ResponseBody
    public ExceResult updateTranPay(@RequestBody WorkPaySeanList uatmzpdsummary) throws Exception {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        List<WorkSeanVoEntity> payVoEntities = uatmzpdsummary.getAttfjgdlist();
        String year = uatmzpdsummary.getYear();
        Integer quarter = Integer.valueOf(uatmzpdsummary.getQuarter());

        //worksean to workpay
        List<WorkPayVoEntity> wps = new ArrayList<>();

        new SeasonToItem(payVoEntities, year, quarter, wps).invoke();

        try {
            if (wps.size() > 0) {
                int iResult = iPayAssessmentService.updateWorkPayList(wps);
                if (iResult > 0) {
                    result.setCode(200);
                    result.setResult(iResult);
                    result.setMsg("操作成功");
                } else {
                    result.setCode(300);
                    result.setResult(iResult);
                    result.setMsg("操作失败");
                }
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }

        return result;
    }

    //update_work_pay状态改变
    @RequestMapping(value = "/update_work_pay_status", method = RequestMethod.POST)
    @ResponseBody
    public ExceResult summaryPayUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            String year = request.getParameter("year");
            String quarter = request.getParameter("quarter");
            String orgid = request.getParameter("orgid");
            String strstatus = request.getParameter("status");

//            Long orgsummaryid = Long.parseLong(strorgsummaryid);
            int status = Integer.parseInt(strstatus);

            String where = "";
            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }
            if (quarter != null && quarter.length() > 0) {
                where += " AND quarter=" + quarter;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }
            if (orgid != null && orgid.length() > 0) {
                where += " AND orgid=" + orgid;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }

            int iResult = 0;
            iResult = iPayAssessmentService.UpdateWorkAttStatusWhere(where, status);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }

    //update_work_pay状态改变
    @RequestMapping(value = "/update_work_pay_statusbm", method = RequestMethod.POST)
    @ResponseBody
    public ExceResult summaryPayUpdateBm(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            String year = request.getParameter("year");
            String quarter = request.getParameter("quarter");
            String orgidstrs = request.getParameter("orgids");
            String strstatus = request.getParameter("status");


            String orgids = "(" + orgidstrs.substring(0, orgidstrs.length() - 1) + ")";
            int status = Integer.parseInt(strstatus);

            String where = "";
            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }
            if (quarter != null && quarter.length() > 0) {
                where += " AND quarter=" + quarter;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }
            if (orgids != null && orgids.length() > 0) {
                where += " AND orgid in " + orgids;
            } else {
                result.setCode(300);
                result.setResult(0);
                result.setMsg("操作失败");
                return result;
            }

            int iResult = 0;
            iResult = iPayAssessmentService.UpdateWorkAttStatusWhere(where, status);
            if (iResult > 0) {
                result.setCode(200);
                result.setResult(iResult);
                result.setMsg("操作成功");
            } else {
                result.setCode(300);
                result.setResult(iResult);
                result.setMsg("操作失败");
            }
        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
            ex.printStackTrace();
        }
        return result;
    }


    //工作津贴钱数匹配
    @RequestMapping(value = "/update_work_pay_check", method = RequestMethod.POST)
    @ResponseBody
    public ExceResult summaryPayCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            String year = request.getParameter("year");
            String quarter = request.getParameter("quarter");
            int quarterInt = Integer.parseInt(quarter);
            String orgid = request.getParameter("orgid");


            //1.取出待改变的数据
            String month1 = "";
            String month2 = "";
            String month3 = "";

            String where = "";
            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }
            if (quarterInt > 0) {
                String[] months = getmonth(quarterInt).split(",");
                month1 = months[0];
                month2 = months[1];
                month3 = months[2];
            }

            if (orgid.length() > 0) {
                where += " AND orgid IN (" + orgid + ")";
            }

            List<WorkSeanVoEntity> lst = iPayAssessmentService.getWorkSeanPayEntiy(where, "", month1, month2, month3, month1);

            //2.计算新旧数据是否平衡
            Float downSum = 0f;
            Float addSum = 0f;
            for (int i = 0; i < lst.size(); i++) {
                String workpernum1 = lst.get(i).getWorkpernum1();
                String workpernum2 = lst.get(i).getWorkpernum2();
                String workpernum3 = lst.get(i).getWorkpernum3();
                String upmoney = lst.get(i).getUpmoney();
                if (workpernum1 != null && !workpernum1.equals("")) downSum += Float.valueOf(workpernum1);
                if (workpernum2 != null && !workpernum2.equals("")) downSum += Float.valueOf(workpernum2);
                if (workpernum3 != null && !workpernum3.equals("")) downSum += Float.valueOf(workpernum3);
                if (upmoney != null && !upmoney.equals("")) addSum += Float.valueOf(upmoney);

            }
            //比对合计金额
            if(downSum > addSum){
                result.setCode(300);
                result.setResult(-1);
                float speace = downSum - addSum;
                result.setMsg("所填金额还差"+speace+"元");
            }
            if(downSum<addSum){
                result.setCode(300);
                result.setResult(-1);
                float speace = addSum - downSum;
                result.setMsg("所填金额超出"+speace+"元");
            }
            if(Math.abs(downSum-addSum)<=0){
                result.setCode(200);
                result.setResult(1);
                result.setMsg("匹配成功");
            }

        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("数据异常");
            ex.printStackTrace();
        }
        return result;
    }

    //endregion

    //region 工作津贴审批
    @RequestMapping(value = "/work_pay_sh_list")
    public String AttShList(Model model) {
        try {
            UserEntity user = this.GetLoginUser();
            String userName = user.getRealname();
            String orgname = user.getOrgname();
            int quarter = 1;
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }
            if (quarter == 1){
                year =year -1;
                quarter = 4;
            }
            else {
                quarter--;//默认上个季度
            }
            model.addAttribute("year", year);
            model.addAttribute("username", userName);
            model.addAttribute("quarter", quarter);
            model.addAttribute("orgname", orgname);
//            model.addAttribute("orgid", orgid);
        } catch (Exception ex) {

        }
        return "payassessment/work_pay_sh_list";
    }


    //todo:废弃
    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_workpay_check_list")
    public LayTable<WorkPayVoEntity> GetList(HttpServletRequest request) {

        List<WorkPayVoEntity> lst = null;
        LayTable<WorkPayVoEntity> layTable = new LayTable<WorkPayVoEntity>();
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));

            String year = request.getParameter("year");
            String month = request.getParameter("month");

            String orgid = request.getParameter("orgid");
            String orgsummaryid = request.getParameter("orgsummaryid");

            String realname = request.getParameter("realname");

            String where = "";


            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }
            if (month != null && month.length() > 0) {
                where += " AND month=" + month;
            }

            if (orgid != null && orgid.length() > 0 && !orgid.equals("0")) {
                where += " AND orgid IN (" + orgid + ")";
            } else {
                where += " AND orgid IN (" + this.GetOrgListByRole() + ")";
            }

            if (orgsummaryid != null && orgsummaryid.length() > 0 && !orgsummaryid.equals("0")) {
                where += " AND orgsummaryid=" + orgsummaryid;
            }

            if (realname != null && realname.length() > 0) {
                where += " AND userid IN (SELECT userid FROM t_sys_user WHERE cardno LIKE '%" + realname + "%'  or realname LIKE '%" + realname + "%')";
            }

            int beginrow = (page - 1) * limit;
            int endrow = limit;

            String wherelimit = where + " LIMIT " + beginrow + "," + endrow;


            lst = iPayAssessmentService.getWorkPayVoEntity(wherelimit);
            for (int i = 0; i < lst.size(); i++) {
                int rownum = (page - 1) * limit + (i + 1);
                lst.get(i).setRowNum(rownum);
            }

            int iCount = iPayAssessmentService.getWorkPayVoCountEntity(where);
            layTable.setCode(0);
            layTable.setCount(iCount);
            layTable.setData(lst);

        } catch (Exception e) {
            layTable.setCode(500);
        }
        return layTable;
    }


    //审批列表
    @ResponseBody
    @RequestMapping(value = "/get_org_summary_work_list")
    public LayTable<Map> GetOrgSummaryShList(HttpServletRequest request) {

        List<Map> lst = null;
        LayTable<Map> layTable = new LayTable<Map>();
        try {
            int year = Integer.parseInt(request.getParameter("year"));
            int quarter = Integer.parseInt(request.getParameter("quarter"));
            int lastMonth = Integer.parseInt(getLastMonth(quarter));

            Calendar cal = Calendar.getInstance();
            int currentyear = cal.get(Calendar.YEAR);
            int currentmonth = cal.get(Calendar.MONTH) + 1;
            if (currentyear != year) {
                currentmonth = 12;
            }
            String where = "";
            where += " AND orgid IN (" + this.GetOrgListByRole() + ")";

            //外层状态统一，取一个OK
            lst = iOrgSummaryService.GetOrgSummaryWorkList(where, year, lastMonth, "", currentmonth);

            //int iCount=iAttTbService.GetAttTbListCountByWhere(where);
            //System.out.println(JSONObject.toJSONString(lst));
            layTable.setCode(0);
            layTable.setCount(lst.size());
            layTable.setData(lst);

        } catch (Exception e) {
            e.printStackTrace();
            layTable.setCode(500);
        }
        return layTable;
    }

    @ResponseBody
    @RequestMapping(value = "/createPDF")
    public int uploadBillClient(HttpServletRequest request) {
        BASE64Decoder decoder = new BASE64Decoder();
        try {
            // Base64解码
            byte[] b = decoder.decodeBuffer(request.getParameter("file"));
            String year = request.getParameter("year");
            Integer month = Integer.valueOf(request.getParameter("month"));
            String orgid = request.getParameter("orgid");
            for (int i = 0; i < b.length; ++i) {
                // 调整异常数据
                if (b[i] < 0) {
                    b[i] += 256;
                }
            }
            String quarter = "";
            if (month == 1 || month == 2 || month == 3) {
                quarter = "1";
            }
            if (month == 4 || month == 5 || month == 6) {
                quarter = "2";
            }
            if (month == 7 || month == 8 || month == 9) {
                quarter = "3";
            }
            if (month == 10 || month == 11 || month == 12) {
                quarter = "4";
            }


            String fileName = "workpay/" + year + "/" + quarter + "/" + orgid + "/file.pdf";
            String filePath = "/Users/lizeze/Desktop/a/pdf/";


            filePath = ConfigOption.getInstance().getFileurl() + "/pdf/";
            fileName = filePath + fileName;


            File file = new File(fileName);
            File fileParent = file.getParentFile();
            if (!fileParent.exists()) {
                fileParent.mkdirs();
            }
            OutputStream out = new FileOutputStream(fileName);
            out.write(b);
            out.flush();
            out.close();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return 0;
        }
        return 1;
    }


    @ResponseBody
    @RequestMapping(value = "/showPDF")
    public String lookPdf(HttpServletRequest request) {
        List<Map> lst = null;

        try {
            String yearstr = request.getParameter("year");
            int quarter = Integer.valueOf(request.getParameter("quarter"));

            List<Configure> configureList = new ArrayList<>();
            configureList = configureService.getAll(" and  code='work'");
            int year = Integer.parseInt(yearstr);
            int month = Integer.parseInt(getLastMonth(quarter));
            List<Map> pdfData = iOrgSummaryService.GetOrgSummaryWorkListPDF(year, quarter, Integer.parseInt(this.GetLoginUser().getSzdw().toString()));
            if (configureList.size() > 0 && pdfData.size() >= 1) {
                Date d = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  ");
                Configure configure = configureList.get(1);

                Date start = sdf.parse(sdf.format(configure.getStarttime()));
                Date end = sdf.parse(sdf.format(configure.getEndtime()));
                Date now = sdf.parse(sdf.format(d));
                if (start.getTime() <= now.getTime() && end.getTime() >= now.getTime()) {

                    Calendar cal = Calendar.getInstance();
                    int currentyear = cal.get(Calendar.YEAR);
                    int currentmonth = cal.get(Calendar.MONTH) + 1;
                    if (currentyear != year) {
                        currentmonth = 12;
                    }
                    String where = "";
                    where += " AND orgid IN (" + this.GetLoginUser().getSzdw() + ")";


                    lst = iOrgSummaryService.GetOrgSummaryWorkList(where, year, month, "4", currentmonth);

                    if (lst.size() > 0) {

                        String webUrl = "http://127.0.0.1:8081/";
                        webUrl = ConfigOption.getInstance().getWeburl();
                        return webUrl + "pdf/workpay/" + year + "/" + quarter + "/" + this.GetLoginUser().getSzdw() + "/file.pdf";

                    }

                }
            }


        } catch (Exception ex) {

        }

        return "";
    }


    @RequestMapping(value = "/lookPdf")
    public String lookPDf(Model model) {
        try {
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }

            if (quarter == 1){
                year =year -1;
                quarter = 4;
            }
            else {
                quarter--;//默认上个季度
            }
            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);

        } catch (Exception ex) {

        }
        return "payassessment/deptsuboutwork_pay_look";
    }

    //endregion

    //region 工作津贴查看
    @RequestMapping(value = "/work_pay_season_list")
    public String workPaySeanList(Model model) {
        try {
            List<OrgEntity> orglst = getOrgEntities();//按权限暂时取掉
            Calendar cal = Calendar.getInstance();
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int quarter = 1;
            switch (month) {
                case 1:
                case 2:
                case 3:
                    quarter = 1;
                    break;
                case 4:
                case 5:
                case 6:
                    quarter = 2;
                    break;
                case 7:
                case 8:
                case 9:
                    quarter = 3;
                    break;
                case 10:
                case 11:
                case 12:
                    quarter = 4;
                    break;
            }
            if (quarter == 1){
                year =year -1;
                quarter = 4;
            }
            else {
                quarter--;//默认上个季度
            }
            String title = orglst.get(0).getOrgname() + "(" + year + "年第" + quarter + "季度)工作性津贴申报表";
            model.addAttribute("year", year);
            model.addAttribute("quarter", quarter);
            model.addAttribute("orglst", orglst);
            model.addAttribute("title", title);
        } catch (Exception ex) {

        }
        return "payassessment/work_pay_season_list";
    }

    @LoginCheck(description = true)
    @ResponseBody
    @RequestMapping(value = "/get_work_season_list")
    public LayTable<WorkSeanVoEntity> GetworkSeanList(HttpServletRequest request) {
        List<WorkPayVoEntity> orilist = null;
        LayTable<WorkSeanVoEntity> layTable = new LayTable<WorkSeanVoEntity>();
        try {
            String year = request.getParameter("year");
            int quarterInt = Integer.parseInt(request.getParameter("quarter"));
            String month = getLastMonth(quarterInt);
            String orgid = request.getParameter("orgid");
            String where = "";
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));

            String month1 = "";
            String month2 = "";
            String month3 = "";

            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }
            if (quarterInt > 0) {
                String[] months = getmonth(quarterInt).split(",");
                month1 = months[0];
                month2 = months[1];
                month3 = months[2];
            }

            if (orgid.length() > 0) {
                OrgEntity orgentity = iOrgService.GetOrgById(Long.parseLong(orgid));
                where += " AND orgid IN (SELECT orgid FROM t_sys_org WHERE lft>=" + orgentity.getLft() + " AND lft<="
                        + orgentity.getRgt() + ")";
            }

            int beginrow = (page - 1) * limit;
            int endrow = limit;

            String whereLimit = " LIMIT " + beginrow + "," + endrow;
            List<WorkSeanVoEntity> lst = iPayAssessmentService.getWorkSeanPayEntiy(where, whereLimit, month1, month2, month3, month);
            for (int i = 0; i < lst.size(); i++) {
                int rownum = (page - 1) * limit + (i + 1);
                lst.get(i).setRownum(rownum);
                String workpernum1 = lst.get(i).getWorkpernum1();
                String workpernum2 = lst.get(i).getWorkpernum2();
                String workpernum3 = lst.get(i).getWorkpernum3();
                Float downsum = 0f;
                if (workpernum1 != null && !workpernum1.equals("")) downsum += Float.valueOf(workpernum1);
                if (workpernum2 != null && !workpernum2.equals("")) downsum += Float.valueOf(workpernum2);
                if (workpernum3 != null && !workpernum3.equals("")) downsum += Float.valueOf(workpernum3);
//                Float sum = 0f;
//                String WorkMoney1 = lst.get(i).getWorkMoney1();
//                String WorkMoney2 = lst.get(i).getWorkMoney2();
//                String WorkMoney3 = lst.get(i).getWorkMoney3();
//                if (WorkMoney1 != null && !WorkMoney1.equals("")) sum += Float.valueOf(WorkMoney1);
//                if (WorkMoney2 != null && !workpernum2.equals("")) sum += Float.valueOf(WorkMoney2);
//                if (WorkMoney3 != null && !workpernum3.equals("")) sum += Float.valueOf(WorkMoney3);
//                sum = sum - downsum;
                downsum = 0 -downsum;
                if(downsum != 0){
                    if(lst.get(i).getDownreason()==null||lst.get(i).getDownreason().equals("")){
                        lst.get(i).setDownreason("根据考勤情况扣减");
                    }
                }

                //不是钱合计，而是减扣金额合计
                lst.get(i).setWorkpernumsum(downsum.toString());
            }
//             where += " AND month in ("+month1+","+month2+","+month3+")";
////            int iCount=iPayAssessmentService.getWorkPayVoCountEntity(where);
            List<WorkSeanVoEntity> lstcount = iPayAssessmentService.getWorkSeanPayEntiy(where, "", month1, month2, month3, month);
            int iCount = lstcount.size();
            layTable.setCode(0);
            layTable.setCount(iCount);
            layTable.setData(lst);

        } catch (Exception e) {
            layTable.setCode(500);
        }
        return layTable;
    }


    //endregion

    //region 工作津贴导出
    @ResponseBody
    @RequestMapping(value = "/export_excel")
    public ExceResult ExportExcel(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            String year = request.getParameter("year");
            String month = request.getParameter("month");
            String quarter = request.getParameter("quarter");
            int quarterInt = Integer.parseInt(quarter);
            String orgid = request.getParameter("orgid");
            String realname = request.getParameter("realname");


            String month1 = "";
            String month2 = "";
            String month3 = "";

            String where = "";

            if(month == null){
                month = getLastMonth(quarterInt);
            }

            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }
            if (quarterInt > 0) {
                String[] months = getmonth(quarterInt).split(",");
                month1 = months[0];
                month2 = months[1];
                month3 = months[2];
            }

            if (orgid.length() > 0) {
                OrgEntity orgentity = iOrgService.GetOrgById(Long.parseLong(orgid));
                where += " AND orgid IN (SELECT orgid FROM t_sys_org WHERE lft>=" + orgentity.getLft() + " AND lft<="
                        + orgentity.getRgt() + ")";
            }

            if (realname != null && realname.length() > 0) {
                where += " AND userid IN (SELECT userid FROM t_sys_user WHERE cardno LIKE '%" + realname + "%'  or realname LIKE '%" + realname + "%')";
            }

            List<WorkSeanVoEntity> lst = iPayAssessmentService.getWorkSeanPayEntiy(where, "", month1, month2, month3, month);
            for (int i = 0; i < lst.size(); i++) {
                //11.4日修改，加入了null就去取部门的逻辑
                String workpernum1="",workpernum2="",workpernum3="";
                Float downsum = 0f;
                lst.get(i).setRownum(i+1);
                long userid = lst.get(i).getUserid();
                if(lst.get(i).getWorkpernum1()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum1(getWorkPernum(year, month1, userid));
                }else {
                    workpernum1 = lst.get(i).getWorkpernum1();
                    downsum += Float.valueOf(workpernum1);
                }
                if(lst.get(i).getWorkpernum2()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum2(getWorkPernum(year, month2, userid));
                }else {
                    workpernum2 = lst.get(i).getWorkpernum2();
                    downsum += Float.valueOf(workpernum2);
                }
                if(lst.get(i).getWorkpernum3()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum3(getWorkPernum(year, month3, userid));
                }else {
                    workpernum3 = lst.get(i).getWorkpernum3();
                    downsum += Float.valueOf(workpernum3);
                }

                downsum = 0 - downsum;

                lst.get(i).setWorkpernumsum(downsum.toString());
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

            //String finalXlsxPath=ConfigOption.getInstance().getTemplateurl()+"/kqtemp.xlsx";
            //String filename=ConfigOption.getInstance().getTemplateurl()+"/考勤_"+sdf.format(new Date())+".xlsx";

            String orgName = lst.get(0).getOrgname();

            String fileName = "jingtie_" + sdf.format(new Date()) + ".xlsx";
            SubheadModel subheadingVo = new SubheadModel();
//            subheadingVo.setHeader("房山市分局"+orgName+"部门第"+quarterInt+"季津贴补助表");
            subheadingVo.setHeader("津贴补助表");
            subheadingVo.setSheetName("第"+quarter+"季在职补助表");
            ExportConfig exportConfig = ExportConfigFactory.getConfig("workpay.xml");
            ExportResult exportResult = FileExportor.getExportResult(exportConfig, lst, subheadingVo);
            String saveUrl = ConfigOption.getInstance().getFileurl();//服务器缓存地址
            String fileRoute = getSavePath(saveUrl);
            String saveFileUrl = fileRoute + fileName;
            OutputStream outputStream = new FileOutputStream(saveFileUrl);
            exportResult.export(outputStream);

            String url = getSavePath(ConfigOption.getInstance().getWeburl()) + fileName;//增加路径，避免重复，增加效率
            result.setCode(200);
            result.setResult(1);
            result.setMsg(url);

        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
        }
        return result;
    }


    @ResponseBody
    @RequestMapping(value = "/export_excel_all")
    public ExceResult ExportExcelAll(HttpServletRequest request, HttpServletResponse response) {
        ExceResult result = new ExceResult();
        result.setCode(400);
        result.setResult(0);
        try {
            String year = request.getParameter("year");
            String month = request.getParameter("month");
            String quarter = request.getParameter("quarter");
            int quarterInt = Integer.parseInt(quarter);
            String where = "";
            if (year != null && year.length() > 0) {
                where += " AND year=" + year;
            }

            String month1 = "";
            String month2 = "";
            String month3 = "";
            if (quarterInt > 0) {
                String[] months = getmonth(quarterInt).split(",");
                month1 = months[0];
                month2 = months[1];
                month3 = months[2];
            }


            List<WorkSeanVoEntity> lst = iPayAssessmentService.getWorkSeanPayEntiy(where, "", month1, month2, month3, month);
            for (int i = 0; i < lst.size(); i++) {
                //11.4日修改，加入了null就去取部门的逻辑
                String workpernum1="",workpernum2="",workpernum3="";
                Float downsum = 0f;
                lst.get(i).setRownum(i+1);
                long userid = lst.get(i).getUserid();
                if(lst.get(i).getWorkpernum1()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum1(getWorkPernum(year, month1, userid));
                }else {
                    workpernum1 = lst.get(i).getWorkpernum1();
                    downsum += Float.valueOf(workpernum1);
                }
                if(lst.get(i).getWorkpernum2()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum2(getWorkPernum(year, month2, userid));
                }else {
                    workpernum2 = lst.get(i).getWorkpernum2();
                    downsum += Float.valueOf(workpernum2);
                }
                if(lst.get(i).getWorkpernum3()==null){//没有，就显示真实所在部门。
                    lst.get(i).setWorkpernum3(getWorkPernum(year, month3, userid));
                }else {
                    workpernum3 = lst.get(i).getWorkpernum3();
                    downsum += Float.valueOf(workpernum3);
                }

                downsum = 0 - downsum;

                lst.get(i).setWorkpernumsum(downsum.toString());
            }


            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

            String fileName = "jingtieall_" + sdf.format(new Date()) + ".xlsx";
            SubheadModel subheadingVo = new SubheadModel();
            subheadingVo.setHeader("津贴补助表");
            subheadingVo.setSheetName("第"+quarter+"季在职补助表");
            ExportConfig exportConfig = ExportConfigFactory.getConfig("workpay.xml");
            ExportResult exportResult = FileExportor.getExportResult(exportConfig, lst, subheadingVo);
            String saveUrl = ConfigOption.getInstance().getFileurl();//服务器缓存地址
            String fileRoute = getSavePath(saveUrl);
            String saveFileUrl = fileRoute + fileName;
            OutputStream outputStream = new FileOutputStream(saveFileUrl);
            exportResult.export(outputStream);

            String url = getSavePath(ConfigOption.getInstance().getWeburl()) + fileName;//增加路径，避免重复，增加效率
            result.setCode(200);
            result.setResult(1);
            result.setMsg(url);

        } catch (Exception ex) {
            result.setCode(500);
            result.setResult(0);
            result.setMsg("操作异常");
        }
        return result;
    }
    //endregion


    public static String getSavePath(String url) {
//        todo:最好动态获取，改为动态的路径
        String savePath = url + "/" + getYear() + "/" + getMonth() + "/" + getDay() + "/";
        File dirPath = new File(savePath);
        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }
        return savePath;
    }

    private class SeasonToItem {
        private List<WorkSeanVoEntity> payVoEntities;
        private String year;
        private Integer quarter;
        private List<WorkPayVoEntity> voEntities;

        public SeasonToItem(List<WorkSeanVoEntity> payVoEntities, String year, Integer quarter, List<WorkPayVoEntity> voEntities) {
            this.payVoEntities = payVoEntities;
            this.year = year;
            this.quarter = quarter;
            this.voEntities = voEntities;
        }

        public void invoke() {
            for (WorkSeanVoEntity payVo : payVoEntities) {
                for (int i = 0; i < 3; i++) {
                    WorkPayVoEntity vo = new WorkPayVoEntity();
                    vo.setCardno(payVo.getCardno());
                    vo.setUserid(payVo.getUserid());
                    vo.setRealname(payVo.getRealname());
                    vo.setOrgid(payVo.getOrgid());
                    vo.setOrgname(payVo.getOrgname());
                    vo.setUserstatus(payVo.getUserstatus());
                    vo.setUpmoney(payVo.getUpmoney());
                    vo.setUpreason(payVo.getUpreason());

                    vo.setDownreason(payVo.getDownreason());
                    vo.setStatus(payVo.getStatus());
                    vo.setYear(year);
                    if (quarter == 1) {
                        if (i == 0) {
                            vo.setMonth("1");
                            vo.setLostMoney(payVo.getWorkpernum1());
                        }
                        if (i == 1) {
                            vo.setMonth("2");
                            vo.setLostMoney(payVo.getWorkpernum2());
                        }
                        if (i == 2) {
                            vo.setMonth("3");
                            vo.setLostMoney(payVo.getWorkpernum3());
                        }
                    }
                    if (quarter == 2) {
                        if (i == 0) {
                            vo.setMonth("4");
                            vo.setLostMoney(payVo.getWorkpernum1());
                        }
                        if (i == 1) {
                            vo.setMonth("5");
                            vo.setLostMoney(payVo.getWorkpernum2());
                        }
                        if (i == 2) {
                            vo.setMonth("6");
                            vo.setLostMoney(payVo.getWorkpernum3());
                        }
                    }
                    if (quarter == 3) {
                        if (i == 0) {
                            vo.setMonth("7");
                            vo.setLostMoney(payVo.getWorkpernum1());
                        }
                        if (i == 1) {
                            vo.setMonth("8");
                            vo.setLostMoney(payVo.getWorkpernum2());
                        }
                        if (i == 2) {
                            vo.setMonth("9");
                            vo.setLostMoney(payVo.getWorkpernum3());
                        }
                    }
                    if (quarter == 4) {
                        if (i == 0) {
                            vo.setMonth("10");
                            vo.setLostMoney(payVo.getWorkpernum1());
                        }
                        if (i == 1) {
                            vo.setMonth("11");
                            vo.setLostMoney(payVo.getWorkpernum2());
                        }
                        if (i == 2) {
                            vo.setMonth("12");
                            vo.setLostMoney(payVo.getWorkpernum3());
                        }
                    }
                    if(vo.getLostMoney()!=null && isNumberd(vo.getLostMoney()))
                        voEntities.add(vo);
                }
            }
        }
    }

    public boolean isNumberd(String str){
        for (int i = 0; i < str.length(); i++)
        {
            if(str.charAt(i)=='.') continue;
            if (!Character.isDigit(str.charAt(i)))
            {
                return false;
            }
        }
        return true;
    }

}
